<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 求任意两个数的和
        function getSum (n1, n2) {
            n2 = n2 === undefined ? 1 : n2;
            var sum = n1 + n2;
            return sum;
        }
        var sum1 = getSum(1);
        var sum2 = getSum(5,6);
        var sum3 = getSum(8,8);
        console.log(sum1);
        console.log(sum2);
        console.log(sum3);


        // 求任意两个数之间的和
        function getSum1 (start, end) {
            var sum = 0;
            for (var i = start; i <= end; i++) {   
               sum += i; 
            }
            return sum;
        }
        console.log(getSum1(1,100));
        console.log(getSum1(1,5));



    </script>
</body>
</html>